home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 908 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: digex.net!not-for-mail
  2. From: jdc@access2.digex.net (John Cochran)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q.: How does strtol() handles overflows?
  5. Date: 9 Jan 1996 22:55:19 -0500
  6. Organization: Express Access Online Communications, Greenbelt, MD USA
  7. Message-ID: <4cvdb7$4ml@access2.digex.net>
  8. References: <4cuc2h$gup@news.netvision.net.il>
  9. NNTP-Posting-Host: access2.digex.net
  10.  
  11. In article <4cuc2h$gup@news.netvision.net.il>,
  12. Ami Simchoni <simchoni@netvision.net.il> wrote:
  13. >Hi,
  14. >
  15. >I am trying to make a rubust ascii-to-decimal function which handles 
  16. >input errors and overflows. I want to rely on the standard library as 
  17. >much as possible.
  18. >
  19. >Borland C++ 3.1 and 4.02 doumentation says if an overflow occurs strtol 
  20. >just returns zero - which is not satisfactory, of course.
  21. >
  22. >The BC++3.1 library source which I have, however, sets errno to ERANGE 
  23. >and returns LONG_MIN or LONG_MAX on overflow. This appears both in the 
  24. >code and in the comments.
  25. >
  26. >Does anybody know what the standard says about it?
  27. >
  28. >Thanks,
  29. >Uri. 
  30. >
  31.  
  32. Section 7.10.1.5 under returns:
  33.  
  34.    The strtol function returns the converted value, if any.  If no conversion
  35.    could be performed, zero is returned.  If the correct value is outside the
  36.    range of representable values, LONG_MAX or LONG_MIN is returned (according
  37.    to the sign of the value), and the value of the macro ERANGE is stored in 
  38.    errno.
  39.  
  40.  
  41.